
require 'rake'
require 'rake/rdoctask'


task :default do
  puts "Try 'rake console' for some fun:)"
end

task :doc do
  require 'rdoc/rdoc'
  rdoc = RDoc::RDoc.new
  options = [] <<
    # set main page to README
    '--main' << 'README' << 
    # include readme
    'README' <<
    # include files under this dir
    '.' << 
    # set title
    '--title' << 'Drunken Master' <<
    # rebuild even if no changes were made
    '--force-update' <<
    # set ouput dir to doc
    '-o' << 'doc'
    # no tests
    '-x' << 'test\\.rb$|test' 
  
  # show how the command would look
  puts 'rdoc '+options.join(' ')
  
  #perform the command
  rdoc.document(options)
end

task :stats do
  begin
    s = DrunkenMaster::Util::CodeStats.new(
      :root => "."
    )
    Dir.new('.').each do |filename|
      if filename[0,1]!= '.' && File.directory?(filename)
        s.include_dir(filename, filename)
      end
    end
    s.print_report
  rescue
    puts "#{$!}\n#{$!.backtrace.join("\n")}"
  end
end

task :console do
  #thanks to http://nhw.pl/wp/2008/01/17/i-want-my-console
  irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'  

  libs =  " -r irb/completion"  
  libs << " -r include.rb"
  exec "#{irb} #{libs} --simple-prompt"
end


namespace :dm do
  task :tests do
    require File.dirname(__FILE__)+'/../run_tests.rb'
  end
  
  task :stats do
    begin
      s = DrunkenMaster::Util::CodeStats.new(
        :root => File.dirname(__FILE__) + "/../lib"
      )
      s.include_dir("application", "application")
      #s.include_dir("persistence", "persistence")
      s.include_dir("visual", "visual")
      s.include_dir("util", "util")
      s.include_dir("loader", "../loader")
      s.include_dir("magic", "../magic")
      #s.include_dir("rake", "../rake")
      s.print_report
    rescue
      puts "#{$!}\n#{$!.backtrace.join("\n")}"
    end
  end
end




